﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace EbbinghausWord.Common
{
    /// <summary>
    /// 安全打开各种Task
    /// </summary>
    public static class SefeTask
    {
        private static bool _isSafeTask = true;

        /// <summary>
        /// 重置安全创建任务的标志
        /// </summary>
        public static void ResetSafelyTaskFlag()
        {
            _isSafeTask = true;
        }

        /// <summary>
        /// 安全创建任务
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T SafelyCreateTask<T>() where T : new()
        {
            var t = default(T);

            if (_isSafeTask)
            {
                t = new T();
                _isSafeTask = false;
            }
            return t;
        }
    }
}
